$(function (){
    $("#register_btn").on("click",function (){
        var username= $('[name="username"]').val();
        var mobile = $('[name="mobile"]').val();
        var password = $('[name="password"]').val();
        // console.log(password)
        var againPass = $('[name="againPass"]').val();
        // console.log(againPass)
        var vCode=$('[name="vCode"]').val();

        // console.log(username);

        if(!username){
            mui.toast("请输入用户名");
            return;
        }
        if(mobile.length < 11){
            mui.toast("请输入合法手机号码");
            return;
        }
        if(password != againPass){
            mui.toast("两次密码输入不相同");
            return;
            
        }
        $.ajax({
            type:'post',
            url:'/user/register',
            data:{
                username:username,
                mobile:mobile,
                password:password,
                vCode:vCode,
            },
            success:function(res){
                alert("注册成功");
                setTimeout(function(){
                    location.href = "login.html";
                },2000)
            }
        })
    })

// 给获取验证码注册点击事件，在控制台输入验证码
$("#getCode").on("click",function(){

    if($(this).hasClass("active")){
        return
    } else {
        $(this).addClass("active");
        $(this).text("正在请求...");
        setTimeout(()=>{
            $(this).removeClass("active");
            $(this).text("再次获取验证码");
        },2000)
    }

    $.ajax({
        url:'/user/vCode',
        type:'get',
        success:function(res){
            console.log(res.vCode);
            
        }
    })
})




})
